package com.controller;

import com.common.utils.AjaxResult;
import com.system.service.SysUserService;
import com.vo.LoginVo;
import com.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author yz
 * @data: 2022/4/6 22:18 星期三
 * @file : LoginController.java
 */

@Controller
public class LoginController {


    @Autowired
    private SysUserService sysUserService;


    /**
     * 登录功能
     *
     * @param loginVo
     * @return
     */
    @PostMapping("/toLogin")
    @ResponseBody
    public AjaxResult toLogin(@RequestBody LoginVo loginVo, HttpServletRequest request, HttpServletResponse response) {
        return sysUserService.toLogin(loginVo, request, response);
    }

    /**
     * 强行登录
     *
     * @param loginVo
     * @return
     */
    @PostMapping("/toLoginTo")
    @ResponseBody
    public AjaxResult toLoginTo(@RequestBody LoginVo loginVo, HttpServletRequest request, HttpServletResponse response) {
        return sysUserService.toLoginTo(loginVo, request, response);
    }

    /**
     * 退出登录
     *
     * @param userVO
     * @return
     */
    @GetMapping("/logout")
    @ResponseBody
    public AjaxResult logout(UserVO userVO) {
        return sysUserService.logout(userVO);
    }

}


